<?php
/**
 * Created by PhpStorm.
 * User: xiangfeng
 * Date: 2022/4/11
 * Time: 7:07 AM
 */

namespace app\api\controller;


use app\api\http\exceptions\ApiErr;
use app\api\http\exceptions\ApiExceptions;
use app\api\service\FileService;

class File extends BaseApi
{
    /**
     * @throws ApiExceptions
     */
    public function uploadFileToOss()
    {
        $param = request()->param();
        $type = isset($param['type']) ? (int)$param['type'] : 0;
        /***************************** 文件上传OSS *****************************/
        if (!$_FILES) {
            throw new ApiExceptions(ApiErr::PLEASE_CONFIRM_UPLOAD_FILE);
        }
        $file = is_array($_FILES['files']['tmp_name']) ? $_FILES['files']['tmp_name'] : explode(" ", $_FILES['files']['tmp_name']);
        switch ($type) {
            default:
                $res = FileService::uploadImageFile($file, 'image/', 1, '', 0, 0);
        }
        return $this->jsonSuccessResponse($res['msg']);
    }
}